package com.parking.carsystem.parkingchargesystem.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.google.gson.Gson;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.parking.carsystem.parkingchargesystem.R;
import com.parking.carsystem.parkingchargesystem.common.Constant;
import com.parking.carsystem.parkingchargesystem.module.InvoiceUrlModel;

import butterknife.BindView;
import butterknife.ButterKnife;

public class InvoiceMessageUrlActivity extends BaseActivity implements View.OnClickListener {
    @BindView(R.id.back)
    ImageView back;
    @BindView(R.id.setting)
    TextView setting;
    @BindView(R.id.text)
    TextView text;
    @BindView(R.id.title_bg)
    RelativeLayout titleBg;
    @BindView(R.id.show_invoice_message)
    ImageView showInvoiceMessage;
    @BindView(R.id.invoice_title)
    TextView invoiceTitle;
    @BindView(R.id.invoice_title_msg)
    TextView invoiceTitleMsg;
    @BindView(R.id.invoice_title_layout)
    RelativeLayout invoiceTitleLayout;
    @BindView(R.id.invoice_status)
    TextView invoiceStatus;
    @BindView(R.id.invoice_status_msg)
    TextView invoiceStatusMsg;
    @BindView(R.id.invoice_open)
    TextView invoiceOpen;
    @BindView(R.id.invioce_status_layout)
    RelativeLayout invioceStatusLayout;
    @BindView(R.id.invoice_number)
    TextView invoiceNumber;
    @BindView(R.id.invoice_number_msg)
    TextView invoiceNumberMsg;
    @BindView(R.id.invoice_number_layout)
    RelativeLayout invoiceNumberLayout;
    @BindView(R.id.invoice_address)
    TextView invoiceAddress;
    @BindView(R.id.invoice_address_msg)
    TextView invoiceAddressMsg;
    @BindView(R.id.invoice_address_layout)
    RelativeLayout invoiceAddressLayout;
    @BindView(R.id.invoice_allmessage)
    RelativeLayout invoiceAllmessage;
    @BindView(R.id.bill_message)
    RelativeLayout billMessage;
    @BindView(R.id.not_data)
    ImageView notData;
    private InvoiceUrlModel.DataBean data;

    @Override
    protected int getContentViewId() {
        return R.layout.activity_invoice_message;
    }

    @Override
    public void initView() {
        text.setText("发票信息");
        invoiceAddressMsg.setOnClickListener(this);
    }

    @Override
    public void initData() {
        String invoiceNo = getIntent().getStringExtra("invoiceNo");
        showLoading();
        OkGo.<String>get(Constant.url + Constant.INVOICEGETINVOICEDETAIL)
                .params("invoiceNo", invoiceNo)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        stopLoading();
                        Gson gson = new Gson();
                        InvoiceUrlModel invoiceUrlModel = gson.fromJson(response.body(), InvoiceUrlModel.class);
                        if (invoiceUrlModel.code ==200 && invoiceUrlModel.data != null) {
                            data = invoiceUrlModel.data;
                            invoiceTitleMsg.setText(data.invoiceTitle.name);
                            invoiceStatusMsg.setText(data.createTime);
                            invoiceNumberMsg.setText(data.invoiceNo);
                            invoiceAddressMsg.setText(data.pdfUrl);
                        }else {
                            billMessage.setVisibility(View.GONE);
                            notData.setVisibility(View.VISIBLE);
                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        stopLoading();
                    }
                });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.invoice_address_msg:
                //查看发票详情
                Intent intent = new Intent(this, TbsReaderViewActivity.class);
                intent.putExtra("pdfUrl",data.pdfUrl);
                startActivity(intent);
                break;
        }
    }
}
